package com.javaweb.config.i18n;

import java.util.Locale;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;

import jakarta.servlet.http.HttpServletRequest;

/**
 * 国际化配置
 * @author tank2140896
 * @see com.javaweb.base.BaseInject#getMessage(String messageKey,HttpServletRequest request)
 */
@Configuration
public class I18NConfig {
	
	/**
	 * 处理国际化
	 * <p>
	 * 主要类型（其它方式略）：
	 * 1、按HTTP请求头部解析区域：AcceptHeaderLocaleResolver
	 * 2、按会话属性解析区域：SessionLocaleResolver
	 * 3、按Cookie解析区域：CookieLocaleResolver
	 * 这里通过RequestHeaders里的Accept-Language来进行国际化处理
	 * @return LocaleResolver LocaleResolver
	 */
	@Bean
    public LocaleResolver localeResolver() {
		var acceptHeaderLocaleResolver = new AcceptHeaderLocaleResolver();
		acceptHeaderLocaleResolver.setDefaultLocale(Locale.CHINA);//默认语言
        return acceptHeaderLocaleResolver;
    }
	
}
